package Email;

import java.util.*;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.*;

public class SendEmail
{
	public static boolean sendEmail(String to, String email) {

		// String to="wassim.gabriel@gmail.com";//change accordingly

		//Get the session object
		System.out.println("7amaddaaaaaaa");
		  Properties props = new Properties();
		  props.put("mail.smtp.host", "smtp.gmail.com");
		  props.put("mail.smtp.socketFactory.port", "465");
		  props.put("mail.smtp.socketFactory.class",
		        	"javax.net.ssl.SSLSocketFactory");
		  props.put("mail.smtp.auth", "true");
		  props.put("mail.smtp.port", "465");
		 
		  Session session = Session.getDefaultInstance(props,
		   new javax.mail.Authenticator() {
		   @Override
		protected PasswordAuthentication getPasswordAuthentication() {
		   return new PasswordAuthentication("secproj10@gmail.com","aykalam2013");//change accordingly
		   }
		  });
		 
		//compose message
		  try {
		   MimeMessage message = new MimeMessage(session);
		   message.setFrom(new InternetAddress("secproj10@gmail.com"));//change accordingly
		   message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
		   message.setSubject("Reset Password Request");
		   message.setText(email);
		   
		   //send message
		   Transport.send(message);

		   System.out.println("message sent successfully");
		   return true;
		 
		  } catch (MessagingException e) {e.printStackTrace();return false;}
		 
		 }
	

}
